import { type MenuItem } from '@/models/menu'
export function ObjectParseMenuItem(list: any[] | null, parentList: MenuItem[]) {
  if (list == null) return
  list.forEach((element) => {
    const item: MenuItem = {
      name: element.name,
      route: element.route,
      children: null,
      icon: element.icon,
      isExpand: false
    }
    const list: MenuItem[] = []
    ObjectParseMenuItem(element.children, list)
    if (list.length != 0) item.children = list
    parentList.push(item)
  })
}
export function getLeafNum(menu: MenuItem[]) {
  let count: number = 0
  menu.forEach((val) => {
    if (val.children != null) {
      const second_menu: MenuItem[] = val.children
      second_menu.forEach((val) => {
        if (val.children != null) {
          count += val.children.length
        }
      })
    }
  })
  return count
}
